﻿HmJS.$Import('core.element');

/*
---
version: 1.0.2-0
description: Element.removeTag method
license: MIT-style
download: http://mootools.net/forge/p/element_removetag
source: http://github.com/jaikdean/mootools-element.removetag

authors: [ Jaik Dean ]

requires: core/1.3: [ Element ]
provides: [ Element.removeTag ]
...
*/

/*
How to use
----------
#### HTML
# HTML
<div>
<div id="removeMe">
This text will be in place of the <em>removeMe</em> element.
</div>
</div>

#### JS
# JS
$('removeMe').removeTag();

#### Result
# HTML
<div>
This text will be in place of the <em>removeMe</em> element.
</div>
...
*/

HmJS.register('base.element.eventdelegation', function ($ns) {

	Element.implement({

		removeTag: function () {
			var childNodes = this.childNodes;

			for (var i = childNodes.length - 1; i >= 0; i--) {
				switch (typeOf(childNodes[i])) {
					case 'textnode':
					case 'whitespace':
						this.appendText(childNodes[i].nodeValue, 'after');
						break;

					case 'element':
						$(childNodes[i]).inject(this, 'after');
						break;
				}
			}

			this.destroy();
		}

	});

});
